// import { func_hook } from "../framework/extend/jsex.js";
import { UtilRes } from "../framework/utils/utilres";
import { SkyBox } from "./component/skybox";
import { UIStart } from "./gui/uistart";
import { EntityBase } from "./component/entitybase";
// import { Tree } from "./component/tree";
import { } from "../framework/threeex/loader/GLTFLoader";

/* global THREE */

export class WorldGraph {

    constructor(oScene) {
        this._scene = oScene;
        this.baseGraph();

    }
    //     _stage: undefined,

    //     //扩展绑定
    //     bindWorld: function (oStageobj) {
    //     this._stage = oStageobj;
    //     //bind func
    //     let funcname;
    //     var self = this;
    //     for (var idx in this.EXFUNC_LIST) {
    //         funcname = this.EXFUNC_LIST[idx];
    //         if (!self[funcname]) {
    //             self[funcname] = (function () {
    //                 var _tmpfname = funcname;
    //                 return function () {
    //                     return oStageobj[_tmpfname](arguments[0], arguments[1]);
    //                 };
    //             })();
    //         }
    //     }
    //     //func hook 
    //     func_hook(this, "baseGraph");
    // },

    baseGraph() {
        // var geometry = new THREE.BoxGeometry(200, 200, 200);
        // var material = new THREE.MeshNormalMaterial();

        // var mesh = new THREE.Mesh(geometry, material);
        // this._scene.add(mesh);
        // this._mesh = mesh;

        var light = new THREE.HemisphereLight(0xffffff, 0x444444);
        light.position.set(0, 200, 0);
        this._scene.add(light);

        light = new THREE.DirectionalLight(0xffffff);
        light.position.set(0, 200, 100);
        light.castShadow = true;
        light.shadow.camera.top = 180;
        light.shadow.camera.bottom = -100;
        light.shadow.camera.left = -120;
        light.shadow.camera.right = 120;
        this._scene.add(light);

        this.showTest();

        //skybox 
        // new SkyBox().show(this._scene);
    }

    update() {
        if (this._mesh) {
            this._mesh.rotation.x += 0.005;
            this._mesh.rotation.y += 0.01;
        }
    }

    showStartUI(cbRm) {
        let mainui = new UIStart(UtilRes.editor_uijson("uistart.json"));
        mainui.addToAsync(this._scene);
        mainui.setTap("label_tap", function () {
            mainui.remove();
            if (typeof (cbRm) == "function") {
                cbRm();
            }
        });
    }

    showSucUI() {
        // let sucui = new ui
    }

    showTest() {
        let glb_test = new THREE.GLTFLoader();
        console.log(UtilRes.model("BoomBox.glb"), "--->>UtilRes.model");
        glb_test.load(UtilRes.model("tree02.glb"), (gltf) => {
            console.log("load finish!", gltf);
            // this._scene.add(gltf.scene);

            var boomBox = gltf.scene;
            boomBox.position.set(0, 0.2, 0);
            boomBox.scale.set(200, 200, 200);

            boomBox.traverse(function (object) {

                if (object.isMesh) {

                    // object.material.envMap = reflectionCube;
                    object.geometry.rotateY(- Math.PI);

                }

            });
            this._scene.add(boomBox);
        });
        // this._scene.add(glb_test);
        // glb_test.pos.x = 100;
        // glb_test.pos.y = 100;

        // let gltf_test = new THREE.GLTFLoader(UtilRes.editor_objjson("tree.glb"));
        // this._scene.add(gltf_test);
    }
}